<?php
class ControllerSettingStore extends Controller {
	private $error = array(); 

	public function index() {
    	$this->load->language('setting/store');
    	$this->document->setTitle($this->language->get('heading_title'));
		
    	if ($this->request->server['REQUEST_METHOD'] == 'POST') {
			$this->load->model('setting/setting');
			$this->model_setting_setting->editSetting('config', $this->request->post);
			$this->session->data['success'] = $this->language->get('text_success');
			$this->redirect($this->url->link('setting/store', 'token=' . $this->session->data['token'], 'SSL'));
		}
    	$this->getForm();
  	}
	 
	public function getForm() {
		if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		} else {
			$this->data['error_warning'] = '';
		}
		if (isset($this->session->data['success'])) {
			$this->data['success'] = $this->session->data['success'];
			unset($this->session->data['success']);
		} else {
			$this->data['success'] = '';
		}
		
  		$this->data['breadcrumbs'] = array();
   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => false
   		);
   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('setting/store', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);
		$this->data['action'] = $this->url->link('setting/store', 'token=' . $this->session->data['token'], 'SSL');

		$this->data['token'] = $this->session->data['token'];
		
		$this->data['heading_title'] = $this->language->get('heading_title');
		 
		$this->data['text_yes'] = $this->language->get('text_yes');
		$this->data['text_no'] = $this->language->get('text_no');
		$this->data['text_image_manager'] = $this->language->get('text_image_manager');
 		$this->data['text_browse'] = $this->language->get('text_browse');
		$this->data['text_clear'] = $this->language->get('text_clear');			
				
		$this->data['entry_name'] = $this->language->get('entry_name');
		$this->data['entry_owner'] = $this->language->get('entry_owner');
		$this->data['entry_address'] = $this->language->get('entry_address');
		$this->data['entry_email'] = $this->language->get('entry_email');
		$this->data['entry_telephone'] = $this->language->get('entry_telephone');
		$this->data['entry_fax'] = $this->language->get('entry_fax');
		$this->data['entry_title'] = $this->language->get('entry_title');
		$this->data['entry_meta_keywords'] = $this->language->get('entry_meta_keywords');
		$this->data['entry_meta_description'] = $this->language->get('entry_meta_description');
		$this->data['entry_catalog_limit'] = $this->language->get('entry_catalog_limit');
		$this->data['entry_admin_limit'] = $this->language->get('entry_admin_limit');
		
		$this->data['entry_logo'] = $this->language->get('entry_logo');
		$this->data['entry_icon'] = $this->language->get('entry_icon');
		$this->data['entry_image_category'] = $this->language->get('entry_image_category');
		$this->data['entry_image_thumb'] = $this->language->get('entry_image_thumb');
		$this->data['entry_image_popup'] = $this->language->get('entry_image_popup');
		$this->data['entry_image_product'] = $this->language->get('entry_image_product');
		$this->data['entry_image_additional'] = $this->language->get('entry_image_additional');
		$this->data['entry_image_related'] = $this->language->get('entry_image_related');
		$this->data['entry_image_compare'] = $this->language->get('entry_image_compare');
		$this->data['entry_image_wishlist'] = $this->language->get('entry_image_wishlist');
		$this->data['entry_image_cart'] = $this->language->get('entry_image_cart');
		
		$this->data['entry_language'] = $this->language->get('entry_language');
		$this->data['entry_ssl'] = $this->language->get('entry_ssl');
		$this->data['entry_use_ssl'] = $this->language->get('entry_use_ssl');
				
		$this->data['button_save'] = $this->language->get('button_save');
		$this->data['button_cancel'] = $this->language->get('button_cancel');

		$this->data['tab_store'] = $this->language->get('tab_store');
		$this->data['tab_image'] = $this->language->get('tab_image');
		$this->data['tab_server'] = $this->language->get('tab_server');
		
		$this->load->model('setting/setting');
      	$store_info = $this->model_setting_setting->getSetting('config');
      	
		$this->data['config_name'] = $store_info['config_name'];
		$this->data['config_owner'] = $store_info['config_owner'];
		$this->data['config_address'] = $store_info['config_address'];
		$this->data['config_email'] = $store_info['config_email'];
		$this->data['config_telephone'] = $store_info['config_telephone'];
		$this->data['config_fax'] = $store_info['config_fax'];
		$this->data['config_title'] = $store_info['config_title'];
		$this->data['config_meta_keywords'] = $store_info['config_meta_keywords'];
		$this->data['config_meta_description'] = $store_info['config_meta_description'];
		$this->data['config_catalog_limit'] = $store_info['config_catalog_limit'];
		$this->data['config_admin_limit'] = $store_info['config_admin_limit'];
		
		$this->load->model('tool/image');
		$this->data['no_image'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
		$this->data['config_logo'] = $store_info['config_logo'];
		if (isset($store_info['config_logo']) && file_exists(DIR_IMAGE . $store_info['config_logo']) && is_file(DIR_IMAGE . $store_info['config_logo'])) {
			$this->data['logo'] = $this->model_tool_image->resize($store_info['config_logo'], 100, 100);		
		} else {
			$this->data['logo'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
		}
		$this->data['config_icon'] = $store_info['config_icon'];
		if (isset($store_info['config_icon']) && file_exists(DIR_IMAGE . $store_info['config_icon']) && is_file(DIR_IMAGE . $store_info['config_icon'])) {
			$this->data['icon'] = $this->model_tool_image->resize($store_info['config_icon'], 100, 100);
		} else {
			$this->data['icon'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
		}
		$this->data['config_image_category_height'] = $store_info['config_image_category_height'];
		$this->data['config_image_thumb_width'] = $store_info['config_image_thumb_width'];
		$this->data['config_image_thumb_height'] = $store_info['config_image_thumb_height'];
		$this->data['config_image_popup_width'] = $store_info['config_image_popup_width'];
		$this->data['config_image_popup_height'] = $store_info['config_image_popup_height'];
		$this->data['config_image_product_width'] = $store_info['config_image_product_width']; 
		$this->data['config_image_product_height'] = $store_info['config_image_product_height'];
		$this->data['config_image_category_width'] = $store_info['config_image_category_width'];
		$this->data['config_image_additional_width'] = $store_info['config_image_additional_width'];
		$this->data['config_image_additional_height'] = $store_info['config_image_additional_height'];
		$this->data['config_image_related_width'] = $store_info['config_image_related_width'];
		$this->data['config_image_related_height'] = $store_info['config_image_related_height'];
		$this->data['config_image_compare_width'] = $store_info['config_image_compare_width'];
		$this->data['config_image_compare_height'] = $store_info['config_image_compare_height'];
		$this->data['config_image_wishlist_width'] = $store_info['config_image_wishlist_width'];
		$this->data['config_image_wishlist_height'] = $store_info['config_image_wishlist_height'];
		$this->data['config_image_cart_width'] = $store_info['config_image_cart_width'];
		$this->data['config_image_cart_height'] = $store_info['config_image_cart_height'];
		
		$this->data['config_ssl'] = isset($store_info['config_ssl']) ? $store_info['config_ssl'] : '';
		$this->data['config_use_ssl'] = $store_info['config_use_ssl'];
		$this->data['config_language_id'] = $store_info['config_language_id'];
		
		$this->load->model('localisation/language');
		$this->data['languages'] = $this->model_localisation_language->getLanguages();
		
		$this->template = 'setting/store_form.tpl';
		$this->children = array(
			'common/header',
			'common/footer'
		);
				
		$this->response->setOutput($this->render());
	}
}
?>